//axios的二次封装
import axios from 'axios'
// import router from '../router'
import type { AxiosInstance } from 'axios'
//创建一个Promise对象


const instance:AxiosInstance = axios.create({
  //基准地址
  baseURL: '/',
  //请求超时时间  1分钟
  timeout: 60000,
  //配置请求头，可以不设置
  // headers: {'X-Custom-Header': 'foobar'}
});
interface IOptions{
  url:string;
  method?:string;
  data?:any;
}

//使用自己的instance封装函数myajax()
export function myAjax(options:IOptions) {
  const { url, method = 'get', data = {} } = options
  //我们这里要去请求只能是get或post
  if (method.toUpperCase() === 'GET') {
    return instance.get(url, { params: data })
  } else {
    return instance.post(url, data)
  }
}

